﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using IGIS.Extensions.markup;
using OSGeo.MapGuide;
namespace IGIS.Extensions.markup
{
    public partial class editmarkup : utilityfunctions
    {
        public String errorMsg = null;
        public String errorDetail = null;
       public NameValueCollection args = null;
       public MarkupEditor markupEditor = null;
       public  Dictionary<string, string> markupFeatures = null;
        public EditCommand _editcomm = new EditCommand();
        public bool refreshMap = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                InitializeWebTier();

                args = GetRequestParameters();
                markupEditor = new MarkupEditor(args);
                UnSuccessText.Visible = false;
                String editCommand = GetParameter(args, "EDITCOMMAND");
                if (editCommand != null && editCommand.Length > 0)
                {
                    int cmd = Int32.Parse(editCommand);
                    switch (cmd)
                    {
                        case EditCommand.AddPoint:
                            markupEditor.AddPoint();
                            refreshMap = true;
                            break;
                        case EditCommand.AddLine:
                        case EditCommand.AddLineString:
                            markupEditor.AddLineString();
                            refreshMap = true;
                            break;
                        case EditCommand.AddRectangle:
                        case EditCommand.AddPolygon:
                            markupEditor.AddPolygon();
                            refreshMap = true;
                            break;
                        case EditCommand.AddBuffer:
                            markupEditor.AddBuffer();
                            refreshMap = true;
                            break;
                        case EditCommand.Delete:
                            bool success = markupEditor.DeleteMarkup();
                            if (!success)
                            {
                                UnSuccessText.Visible = true;
                                UnSuccessText.Text = "<div style='background-color:#F5D0D9; border:solid 1px #000000; width:200px; text-align:center;'>÷ééîú øùåîú úçæå÷ä, ÷ùåøä ìøëéá äæä.<br/>ìà ðéúï ìîçå÷ àú äøëéá.</div>";
                            }
                            refreshMap = true;
                            break;
                        case EditCommand.Update:
                            markupEditor.UpdateMarkup();
                            refreshMap = true;
                            break;
                    }
                }
                markupFeatures = markupEditor.GetMarkupFeatures();
            }
            catch (MgException exx)
            {
                errorMsg = exx.GetExceptionMessage();
                errorDetail = exx.GetDetails();
            }

        }
    }
}